//
//  Ellipse.m
//  D3J
//
//  Created by DucHa on 6/18/13.
//  Copyright (c) 2013 doductrung. All rights reserved.
//

#import "Ellipse.h"


@implementation Ellipse

//@dynamic x;
//@dynamic y;
//@dynamic strokeWidth;
//@dynamic strokeColor;
//@dynamic fill;
//@dynamic width;
//@dynamic height;

- (id) initWithX:(CGFloat)x andY:(CGFloat)y andRadius:(NSMutableArray *)radius andId:(NSString *)Id
{
    self = [super init];
    if (self) {
        self.id = Id;
        self.name = @"Ellipse";
        self.x = x;
        self.y = y;
        self.radius = radius;
        self.width = [radius[0] floatValue];
        self.height = [radius[1] floatValue];
        self.strokeWidth = 5.0f;
        
        self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);
        self.backgroundColor = [UIColor clearColor];
        
        self.strokeColor = [UIColor blackColor].CGColor;
        self.fill = [UIColor whiteColor].CGColor;
        
    }
    return  self;
}

- (void) drawRect:(CGRect)rect
{
    
    CGContextRef context = UIGraphicsGetCurrentContext();
    
    CGContextSetStrokeColorWithColor(context, self.strokeColor);
    CGContextSetLineWidth(context, self.strokeWidth);
    
    CGContextSetFillColorWithColor(context, self.fill);
    
    CGRect frame = CGRectMake(self.strokeWidth / 2, self.strokeWidth / 2, self.width, self.height);
    //CGContextFillRect(context, frame);
    
    CGContextFillEllipseInRect(context, frame);
    //CGContextAddEllipseInRect(context, frame);
    CGContextStrokeEllipseInRect(context, frame);
    //CGContextStrokeRect(context, frame);
//    NSLog(@"%f %f",frame.origin.x, frame.origin.y);
//    NSLog(@"%f %f",self.strokeWidth, self.strokeWidth);
}

- (void) resetStrokeWidth:(float)strokeWidth
{
    self.strokeWidth = strokeWidth;
    self.frame = self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);

}

- (void) resetFill:(CGColorRef)fill
{
    [self setFill:fill];
}

- (void) resetStrokeColor:(CGColorRef)strokeColor
{
    [self setStrokeColor:strokeColor];
}

- (void) resetHeight:(float)height
{
    self.height = height;
    self.frame = self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);
}

- (void) resetWidth:(float)width
{
    self.width = width;
    self.frame = self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);
}

- (void) resetX:(float)x
{
    self.x = x;
    self.frame = self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);
}

- (void) resetY:(float)y
{
    self.y = y;
    self.frame = self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);
}

- (void) resetScale:(float)scale
{
    self.width = scale * self.height;
    self.frame = self.frame = CGRectMake(self.x - self.strokeWidth / 2, self.y - self.strokeWidth / 2 , self.width + self.strokeWidth, self.height + self.strokeWidth);
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

@end
